<template>
  <div>
    <div class="plugins-tips">ElementPlus 表格，横向内容过多可以横向移动</div>
    <!-- 表格 -->
    <div>
      <el-table
        v-loading="loading"
        element-loading-text="数据加载中..."
        element-loading-svg-view-box="-10, -10, 50, 50"
        :data="tableData"
        style="width: 100%"
      >
        <el-table-column fixed prop="id" label="编号" width="70" />
        <el-table-column prop="name" label="姓名" width="120" />
        <el-table-column prop="age" label="年龄" width="120" />
        <el-table-column prop="city" label="所在城市" width="120" />
        <el-table-column prop="address" label="地址" width="600" />
        <el-table-column prop="date" label="日期" width="120" />
        <el-table-column fixed="right" label="操作" min-width="140">
          <template #default>
            <el-button link type="primary" size="small" @click="detailsClick">
              详细
            </el-button>
            <el-button link type="primary" size="small" @click="editorClick"
              >编辑</el-button
            >
            <el-button link type="danger" size="small" @click="deleteClick"
              >删除</el-button
            >
          </template>
        </el-table-column>
      </el-table>
    </div>
    <!-- 分页 -->
    <div class="pager">
      <el-pagination
        background
        layout="prev, pager, next"
        :page-count="8"
        :total="50"
      />
    </div>
  </div>
</template>

<script setup>
import { ref, onMounted } from "vue";
//预加载动画
let loading = ref(true);

//加载后执行
onMounted(() => {
  if (loading) {
    setTimeout(setLoadDone, 1500);
  }
});

//定时1.5秒后
const setLoadDone = () => {
  loading.value = false;
};

//详细按钮事件
const detailsClick = () => {
  console.log("详细");
};
//编辑按钮事件
const editorClick = () => {
  console.log("编辑");
};
//删除按钮事件
const deleteClick = () => {
  console.log("删除");
};

const tableData = [
  {
    id: 1,
    name: "王伟",
    age: 22,
    city: "天津",
    address: "天津大学智能与计算学部网络安全学院",
    date: "2024-9-22",
    tag: "学生",
  },
  {
    id: 2,
    name: "张哲",
    age: 22,
    city: "天津",
    address: "天津大学智能与计算学部网络安全学院",
    date: "2024-9-22",
    tag: "学生",
  },
  {
    id: 3,
    name: "胡雪",
    age: 22,
    city: "天津",
    address: "天津大学智能与计算学部网络安全学院",
    date: "2024-9-22",
    tag: "学生",
  },
  {
    id: 4,
    name: "王瑾丽",
    age: 22,
    city: "天津",
    address: "天津大学智能与计算学部网络安全学院",
    date: "2024-9-22",
    tag: "学生",
  },
  {
    id: 5,
    name: "陈宇恒",
    age: 22,
    city: "天津",
    address: "天津大学智能与计算学部网络安全学院",
    date: "2024-9-22",
    tag: "学生",
  },
  {
    id: 6,
    name: "李国立",
    age: 22,
    city: "天津",
    address: "天津大学智能与计算学部网络安全学院",
    date: "2024-9-22",
    tag: "学生",
  },
  {
    id: 7,
    name: "周洪洋",
    age: 22,
    city: "天津",
    address: "天津大学智能与计算学部网络安全学院",
    date: "2024-9-22",
    tag: "学生",
  },
  {
    id: 8,
    name: "王丽芳",
    age: 22,
    city: "天津",
    address: "天津大学智能与计算学部网络安全学院",
    date: "2024-9-22",
    tag: "学生",
  },
  {
    id: 9,
    name: "孙筱月",
    age: 22,
    city: "天津",
    address: "天津大学智能与计算学部网络安全学院",
    date: "2024-9-22",
    tag: "学生",
  },
  {
    id: 10,
    name: "王萍",
    age: 22,
    city: "天津",
    address: "天津大学智能与计算学部网络安全学院",
    date: "2024-9-22",
    tag: "学生",
  },
];
</script>

<style scoped>
.plugins-tips {
  background: rgba(0, 0, 0, 0.1);
  padding: 20px;
  border-radius: 8px;
  margin-bottom: 15px;
}

.pager{
  margin-top: 10px;
}
</style>